<!--
 * @Description: 发放多奖励确认弹窗
 * @Author: liyujie
 * @Date: 2021/05/17
 * @Last Modified by: liyujie
 * @Last Modified time: 2021/05/17
-->
<template>
    <section class="wrapper">
        <el-dialog
            title="发放奖励"
            width="800px"
            :visible.sync="visible"
        >
            <div class="base-info">
                <div
                    class="base-info-title"
                    v-if="type === 'grant'"
                >
                    奖励发放对象
                </div>
                <div
                    class="base-info-title status"
                    :class="formData.award_status === 1 ? 'success' : 'danger'"
                    v-if="type === 'detail'"
                >
                    {{ formData.award_status === 1 ? '奖励已发放' :formData.award_status === 0 ? '奖励未发放' : '拒绝发放' }}
                    <div
                        class="tips"
                        v-if="formData.verify_fail_reason"
                    >（未发放原因：{{ formData.verify_fail_reason }}）
                    </div>
                </div>
                <div class="base-info-form">
                    <div
                        class="base-info-form-item"
                        v-if="type === 'detail'"
                    >
                        <div class="base-info-form-item__content">
                            发放对象
                        </div>
                    </div>
                    <div class="base-info-form-item">
                        <div class="base-info-form-item__label">
                            用户昵称：
                        </div>
                        <div class="base-info-form-item__content">
                            {{ formData.true_name }}
                        </div>
                    </div>
                    <div class="base-info-form-item">
                        <div class="base-info-form-item__label">
                            联系电话：
                        </div>
                        <div class="base-info-form-item__content">
                            {{ formData.phone }}
                        </div>
                    </div>
                </div>
            </div>
            <div class="content-table">
                <div class="table-title">
                    {{ type === 'grant' ? '选择发放奖励的子任务/主任务' : '完成任务情况' }}

                </div>
                <el-table
                    v-if="formData.award_config_data"
                    :data="formData.award_config_data.award_item_list"
                    max-height="240"
                    ref="table"
                    @row-click="handleRadioChange"
                    @selection-change="handleSelectionChange"
                >
                    <el-table-column
                        width="80"
                        align="center"
                        type="selection"
                        v-if="type === 'grant'"
                    />
                    <el-table-column
                        :label="formData.award_config_data.award_item_list[0].require_submit_count_type === 1 ? '主任务' : '子任务'"
                        align="center"
                    >
                        <template slot-scope="scope">
                            {{ formData.award_config_data.award_item_list[0].require_submit_count_type === 1 ? '主任务' : '子任务' }}{{ scope.$index + 1 }}
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="要求数量"
                        prop="require_submit_count"
                        align="center"
                    />
                    <el-table-column
                        label="完成数量"
                        prop="has_submit_count"
                        align="center"
                    />
                    <el-table-column
                        label="奖励类型"
                        align="center"
                    >
                        <template slot-scope="scope">
                            {{ scope.row.type === 1 ? '现金奖励' : '0元购学生券' }}
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="奖励金额/数量"
                        align="center"
                        width="130"
                    >
                        <template slot-scope="scope">
                            {{ scope.row.total_num }}{{ scope.row.type === 1 ? '元' : '张' }}
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="用户端显示金额"
                        align="center"
                        width="130"
                    >
                        <template slot-scope="scope">
                            <div v-if="scope.row.type === 1">{{ scope.row.award_num }}元</div>
                            <div v-else>--</div>
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="任务状态"
                        align="center"
                    >
                        <template slot-scope="scope">
                            <div
                                v-if="scope.row.status === 1"
                                style="color: #2FBDB3;"
                            >
                                进行中
                            </div>
                            <div
                                v-if="scope.row.status === 2"
                                style="color:#333;"
                            >
                                已完成
                            </div>
                            <div
                                v-if="scope.row.status === 3"
                                style="color:#FF3030;"
                            >
                                已结束
                            </div>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
            <div slot="footer">
                <el-button
                    size="medium"
                    style="width: 120px; margin-right: 60px;"
                    @click="visible = false"
                >
                    取消
                </el-button>
                <el-button
                    size="medium"
                    style="width: 120px"
                    type="primary"
                    v-if="type === 'grant'"
                    @click="handleConfirm"
                >
                    确定
                </el-button>
            </div>
        </el-dialog>
    </section>
</template>

<script>
export default {
    name: "GrantMultipleAwardDialog",
    data() {
        return {
            // grant 发放 detail 查看
            type: 'grant',
            visible: false,
            selection: [],
            formData: {},
        };
    },
    methods: {
        show(data, type = 'grant') {
            this.formData = data;
            this.type = type;
            this.visible = true;
        },

        close() {
            this.visible = false;
        },

        /**
         * 点击每一行
         * @param row
         */
        handleRadioChange(row) {
            this.$refs.table.toggleRowSelection(row);
        },

        /**
         * 点击每一行
         * @param selection
         */
        handleSelectionChange(selection) {
            this.selection = selection;
        },

        /**
         * 确定提交
         */
        handleConfirm() {
            this.$emit('confirm', this.selection.map(item => {
                return item.id;
            }).join());
            this.close();
        }
    }
};
</script>

<style scoped lang="less">
.wrapper {
    .base-info {
        border-bottom: 1px solid #EBEEF5;
        margin: 0 48px;

        &-title {
            font-size: 14px;
            font-family: PingFangSC-Medium, PingFang SC;
            font-weight: 500;
            color: #333333;

            &.status {
                font-size: 16px;
                font-family: PingFangSC-Medium, PingFang SC;
                font-weight: 500;
                display: flex;
                align-items: center;
                &.success {
                    color: #2FBDB3;
                }
                &.danger {
                    color: #FF3030;
                }
                .tips {
                    font-size: 12px;
                    font-family: PingFangSC-Regular, PingFang SC;
                    font-weight: 400;
                    color: #999999;
                    margin-left: 12px;
                }
            }
        }

        &-form {
            display: flex;

            &-item {
                display: flex;
                font-size: 14px;
                font-family: PingFangSC-Regular, PingFang SC;
                font-weight: 400;
                margin: 24px 32px 24px 0;

                &__label {
                    color: #888888;
                }

                &__content {
                    color: #333333;
                }
            }
        }
    }

    .content-table {
        margin: 24px 48px 0;

        .table-title {
            font-size: 14px;
            font-family: PingFangSC-Medium, PingFang SC;
            font-weight: 500;
            color: #333333;
            margin-bottom: 12px;
        }

    }

    /deep/ .el-dialog__header {
        padding-top: 10px;
        box-shadow: 0 1px 0 0 rgba(233, 233, 233, 1);
        display: flex;
        align-items: center;
        background: #FAFAFA;
        border-radius: 4px 4px 0 0;

        .el-dialog__title {
            font-weight: 500;
            color: #333;
            font-size: 14px;
        }

        .el-icon-close:before {
            color: rgb(194, 194, 194);
            font-size: 17px;
            font-weight: bold;
        }

        .el-dialog__headerbtn {
            top: 14px;
        }
    }

    /deep/ .el-table__fixed-right {
        right: 6px !important;
    }

    /deep/ .el-dialog__footer {
        text-align: center;
        display: flex;
        align-items: center;
        justify-content: center;
        padding-bottom: 32px;
    }

    /deep/ .el-textarea__inner {
        resize: none;
    }
}
</style>
